package com.hk.developmentlib.utills;

import android.os.UserManager;

import org.xutils.DbManager;
import org.xutils.x;

/**
 * 作者：wl on 2017/7/26 17:31
 * 邮箱：wangl@ixinyongjia.com
 */
public class XUtillsDBManeger {
    private DbManager db;
    private final String DB_NAME = "UserID";
    private final int VERSION = 2;

    public DbManager getDb() {
        return db;
    }

    public void setDb(DbManager db) {
        this.db = db;
    }

    public XUtillsDBManeger(int user_id) {
        DbManager.DaoConfig daoConfig = new DbManager.DaoConfig()
                .setDbName(DB_NAME + user_id)
                .setDbVersion(VERSION)
                .setDbOpenListener(new DbManager.DbOpenListener() {
                    @Override
                    public void onDbOpened(DbManager db) {
                        db.getDatabase().enableWriteAheadLogging();
                        //开启WAL, 对写入加速提升巨大(作者原话)
                    }
                })
                .setDbUpgradeListener(new DbManager.DbUpgradeListener() {
                    @Override
                    public void onUpgrade(DbManager db, int oldVersion, int newVersion) {
                        //数据库升级操作
                    }
                });
        db = x.getDb(daoConfig);
    }


//    private DbManager.DaoConfig getDaoConfig(int user_id) {
//        return daoConfig = new DbManager.DaoConfig()
//                .setDbName(DB_NAME + user_id)
//                .setDbVersion(VERSION)
//                .setDbOpenListener(new DbManager.DbOpenListener() {
//                    @Override
//                    public void onDbOpened(DbManager db) {
//                        db.getDatabase().enableWriteAheadLogging();
//                        //开启WAL, 对写入加速提升巨大(作者原话)
//                    }
//                })
//                .setDbUpgradeListener(new DbManager.DbUpgradeListener() {
//                    @Override
//                    public void onUpgrade(DbManager db, int oldVersion, int newVersion) {
//                        //数据库升级操作
//                    }
//                });
//    }
//
//
//    private DbManager initDBManager(int UserId) {
//        daoConfig = getDaoConfig(UserId);
//        return x.getDb(daoConfig);
//    }

}
